<?php
    
    @header('Content-type:text/html;charset=utf-8');
    @include_once('../php/conn.php');
    @include_once('../php/noparams.php');

    $user = $_POST['user'];

    if(!$user){
        NoParamsErr();
    }

    // 连表查询 
    $sql = "select s.id , s.goodId,s.buynum, g.goodsName,g.goodsImg,g.goodsPrice  from  `shopcart` as s, `goodslist` as g where s.goodId = g.goodsId and s.user = '$user' ";

    $result = mysqli_query($conn,$sql);

    if(!$result){
        $obj = array();
        $obj['status'] = false;
        $obj['detail'] = "sql语句有问题1";
        $obj['sql']  = $sql;
        exit(json_encode($obj));
    }

    $all = array();
    while($item = mysqli_fetch_assoc($result)){
        $item['total'] = number_format($item['goodsPrice'] * $item['buynum'],2);   // 总价格 
        array_push($all,$item);
    }

    $obj = array();
    if(count($all)){
        $obj["status"] = true;
        $obj["detail"] = "查询成功";
        $obj["result"] = $all;
    }else{
        $obj["status"] = false;
        $obj["detail"] = "数据不存在";
    }
    echo json_encode($obj);
?>